﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace Pasta.Medio.Models
{
	public class Settings
	{
		private Config _config = null;

		public Settings( string company, string product )
		{
			_config = new Config(company, product);

			PhotoTypes = GetList(Constants.PhotoTypes, Defaults.PhotoTypes);
			VideoTypes = GetList(Constants.VideoTypes, Defaults.VideoTypes);
			RenamePattern = GetString(Constants.RenamePattern, Defaults.RenamePattern);

			string stagingFolder = Path.Combine( Environment.GetFolderPath( Environment.SpecialFolder.CommonApplicationData), @"Medio\Staging" );
			StagingFolder = GetString(Constants.StagingFolder, stagingFolder);
		}

		private List<string> GetList(string key, string def )
		{
			string setting = _config[key];
			List<String> list = setting.Split(';').Where(e => !String.IsNullOrWhiteSpace(e) ).ToList();
			if (list.Count == 0)
			{
				list.AddRange(def.Split(';'));
			}
			return list;
		}

		private string GetString(string key, string def)
		{
			string setting = _config[key];
			if (String.IsNullOrWhiteSpace(setting))
			{
				setting = def;
			}
			return setting;
		}

		// PhotoTypes
		public List<String> PhotoTypes
		{
			get { return _photoTypes; }
			set
			{
				_photoTypes = value;
				_config[Defaults.PhotoTypes] = String.Join(";", value);
				PhotoTypesString = String.Join("", _photoTypes).Replace("*", "");
			}
		}
		private List<String> _photoTypes = new List<string>();

		// PhotoTypesString
		public String PhotoTypesString { get; set; }

		// VideoTypes
		public List<String> VideoTypes
		{
			get { return _videoTypes; }
			set
			{
				_videoTypes = value;
				_config[Defaults.VideoTypes] = String.Join(";", value);
				VideoTypesString = String.Join("", _videoTypes).Replace("*", "");
			}
		}
		private List<String> _videoTypes = new List<string>();

		// VideoTypesString
		public String VideoTypesString { get; set; }

		// Patterns
		public String RenamePattern { get; set; }

		// StagingFolder
		public String StagingFolder { get; set; }
	}
}
